//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_vehiclescripts.sqf"
#include "x_setup.sqf"

GVAR(player_in_vec) = true;
private ["_vec", "_isAir"];
_vec = vehicle player;
if ((_vec isKindOf "ParachuteBase") || {_vec isKindOf "BIS_Steerable_Parachute"}) exitWith {};
_isAir = _vec isKindOf "Air";
__TRACE_2("d_fnc_vehicleScripts","_vec","_isAir");
if (_isAir) then {
	if (_vec isKindOf "Helicopter" && {GVAR(WithChopHud)}) then {
		0 spawn FUNC(chop_hudsp);
	};
	if (GVAR(pilots_only) == 0 && {!(call FUNC(isPilotCheck))} && {player == driver _vec}) then {
		if (isEngineOn _vec) then {
			_vec engineOn false;
			player action ["engineOff", _vec];
		};
		player action ["eject", _vec];
		hintSilent localize "STR_DOM_MISSIONSTRING_1417";
	};
} else {
	if (GVAR(vechud_on) == 0 && {((_vec isKindOf "LandVehicle" && {!(_vec isKindOf "StaticWeapon")}) || {_vec isKindOf "StaticWeapon" && {!(_vec isKindOf "StaticATWeapon")}})}) then {
		0 spawn FUNC(vec_hudsp);
	};
	if (GVAR(MHQDisableNearMT) != 0 && {!GVAR(playerInMHQ)}) then {
		_vt = GV(_vec,GVAR(vec_type));
		if (!isNil "_vt" && {_vt == "MHQ"}) then {
			GVAR(playerInMHQ) = true;
			0 spawn FUNC(mhqCheckNearTarget);
		};
	};
};
if (GVAR(with_ranked)) then {
	if (_vec isKindOf "Car" || {_vec isKindOf "Helicopter"}) then {
		0 spawn FUNC(playervectrans);
	};
	call FUNC(playerveccheck);
};
if (GVAR(without_vec_ti) == 0) then {
	_vec disableTIEquipment true;
};
// TODO
// No repair stations or similar buildings found in A3
// if (GVAR(WithRepStations) == 0) then {execFSM "fsms\RepStation.fsm"};

if (toUpper (typeOf _vec) in GVAR(check_ammo_load_vecs)) then {
	#ifndef __TT__
	[GVAR(AMMOLOAD)] execFSM "fsms\AmmoLoad.fsm";
	#else
	if (GVAR(player_side) == blufor) then { // TODO: check if blufor uses ammoload and opfor ammoload2
		[GVAR(AMMOLOAD)] execFSM "fsms\AmmoLoad.fsm";
	} else {
		[GVAR(AMMOLOAD2)] execFSM "fsms\AmmoLoad.fsm";
	};
	#endif
};